//
//  RetweetedStatuesView.m
//  SinaWeibo
//
//  Created by Apple on 16/8/20.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "RetweetedStatuesView.h"
#import "StatuesModel.h"
#import "PhotoCell.h"

#import "MJPhoto.h"
#import "MJPhotoBrowser.h"

#define kMargin 10

@interface  RetweetedStatuesView()

@property (weak, nonatomic) IBOutlet UILabel *retweetedConteLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *retweetedViewHeight;

@property (weak, nonatomic) IBOutlet UICollectionView *photoCollectionView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *photoCollectionViewHeight;

@end


@implementation RetweetedStatuesView

-(void)awakeFromNib{
    
    self.retweetedConteLabel.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - 20;
    
}


-(void)setStatueModel:(StatuesModel *)statueModel{
    
    [super setStatueModel:statueModel];
    
    
    if (statueModel != nil) {
        self.hidden = NO;
        [self steupRetweeted];
    }else{
        self.hidden = YES;
        self.retweetedViewHeight.constant = 0;
    }
    
}

-(void)steupRetweeted{
    
    //设置转发征文
    self.retweetedConteLabel.text = [NSString stringWithFormat:@"转发@%@//%@",self.statueModel.user.name,self.statueModel.text];
    
    //计算文字高度
    CGFloat contentLabelHeight = [self.retweetedConteLabel systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + kMargin;

    //计算collectionView高度
    NSInteger count = self.statueModel.pic_urls.count;
    NSInteger maxCol = 3;
    NSInteger row = 0;
    CGFloat cellHeight = 110;
    
    if (count >0 ) {
        
        if (count % maxCol == 0) {
            row = count / maxCol;
        }else{
            row = count / maxCol + 1;
        }
        
        CGFloat photophotoCollectionViewHeight = row * cellHeight +(row + 1 )*kMargin ;
        
        self.photoCollectionViewHeight.constant = photophotoCollectionViewHeight;
    }else{
        
        self.photoCollectionViewHeight.constant = 0;
    }

    [self.photoCollectionView reloadData];
    
    self.retweetedViewHeight.constant = contentLabelHeight + self.photoCollectionViewHeight.constant;
    
}

@end
